﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web.Admin.Corp
{
    public partial class Image_new : System.Web.UI.Page
    {
        string currentCorpID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["id"] == null)
            {
                Response.Write("<script>window.close();</script>");
            }
            else
            {
                currentCorpID = Request["id"].ToString();
                UpLoad1.GUID = currentCorpID;
            }
        }

        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string filePath = UpLoad1.FullPath;
                if (string.IsNullOrEmpty(filePath))
                {
                    Response.Write("<script> alert('请选择需要上传的文件!') </script>");
                    return;
                }
                if (!string.IsNullOrEmpty(filePath) && !string.IsNullOrEmpty(currentCorpID))
                {
                    Model.CorpInfoData corpInfo = new Model.CorpInfoData();
                    filePath = filePath.Replace('\\', '/');
                    filePath = filePath.Replace("//", "/");
                    int flag = corpInfo.UpdateImage(filePath, currentCorpID);
                    if (flag > 0)
                    {
                        Response.Write("<script> alert('上传成功') </script>");
                    }
                    else
                    {
                        Response.Write("<script> alert('未能上传成功，请重新上传！') </script>");
                    }
                }
                else
                {
                    Response.Write("<script> alert('上传成功,未能正常写入数据库!') </script>");
                    WebHelper.Pages.Log.WriteLog(string.Format("该文件上传成功，数据库保存错误；文件路径：{0}", filePath), "ImageUpload");
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script> alert('服务器错误，请稍候上传!') </script>");
                WebHelper.Pages.Log.WriteLog(string.Format("时间{1},上传图片时候出错：{0}", ex.Message,DateTime.Now.ToString()), "ImageUpload");
            }
        }
    }
}
